Skip to content

feat: add gemini-nano-dev skill for Chrome built-in AI - #43

Open
fauzan171 wants to merge 1 commit into
google-gemini:mainfrom
fauzan171:feat/gemini-nano-skill
Open

feat: add gemini-nano-dev skill for Chrome built-in AI#43
fauzan171 wants to merge 1 commit into
google-gemini:mainfrom
fauzan171:feat/gemini-nano-skill

Conversation

@fauzan171

Copy link
Copy Markdown

Description

Add a comprehensive skill for building web applications and Chrome Extensions using Chrome's built-in AI powered by Gemini Nano (on-device model).

Fixes #17

Changes

New: skills/gemini-nano-dev/SKILL.md

A complete skill covering all Chrome built-in AI APIs:

  • Prompt API (LanguageModel) — General-purpose text generation with system prompts, conversation history, and response prefixes
  • Multimodal input — Image understanding (Blob, HTMLImageElement, HTMLCanvasElement, etc.) and audio understanding (AudioBuffer, ArrayBuffer, Blob)
  • Structured output — JSON Schema-constrained responses via responseConstraint
  • Session management — Context window tracking, overflow handling, cloning, and destroying sessions
  • Specialized APIs:
    • Summarizer API — One-click text summarization
    • Writer API — Purpose-driven text generation
    • Rewriter API — Rewrite text with different tone/length
    • Proofreader API — Grammar and spelling correction
    • Language Detector API — Detect input language
    • Translator API — On-device translation
  • Chrome Extensions — Extension-specific guidance including model parameters (topK, temperature)
  • Localhost setup — Chrome flags for development
  • Best practices — 10 actionable tips for production use

Modified: README.md

Added gemini-nano-dev to the skills table.

Testing

  • Skill follows the same format and conventions as existing skills (gemini-api-dev, gemini-live-api-dev, gemini-interactions-api)
  • All code examples are based on official Chrome developer documentation
  • Frontmatter includes proper name and description fields

Related

Add a comprehensive skill for building web applications and Chrome
Extensions using Chrome's built-in AI powered by Gemini Nano.

The skill covers:
- Prompt API (LanguageModel) for text generation
- Multimodal input (image and audio understanding)
- Structured output with JSON Schema constraints
- Session management (context window, cloning, destroying)
- Specialized APIs: Summarizer, Writer, Rewriter, Proofreader,
  Language Detector, and Translator
- Chrome Extensions integration
- Hardware requirements and localhost setup
- Best practices for on-device AI development

Also updates README.md to include the new skill in the skills table.

Fixes google-gemini#17

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces the gemini-nano-dev skill, providing comprehensive documentation and code examples for building web applications and Chrome Extensions using Chrome's built-in AI (Gemini Nano). The documentation covers the Prompt API, multimodal inputs, structured outputs, and specialized APIs like Summarizer and Translator. Feedback focuses on correcting API access patterns by using the ai namespace, fixing environment-specific code (replacing Node.js APIs with browser-compatible ones), and ensuring correct property and method names for session management and capabilities.

Always check if the model is ready before creating a session:

```javascript
const availability = await LanguageModel.availability({

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The Chrome built-in AI APIs are accessed via the window.ai namespace (e.g., ai.languageModel, ai.summarizer). Using the capitalized interface names like LanguageModel as global entry points is incorrect and will result in a ReferenceError. This pattern should be updated throughout the document for all APIs (Summarizer, Writer, etc.).

Suggested change
const availability = await LanguageModel.availability({
const availability = await ai.languageModel.availability({
References
  1. Code examples in skill documentation should be minimal, demonstrating only the core SDK functionality. Avoid adding boilerplate like error handling, as the goal is to showcase SDK usage, not teach general coding practices.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is outdated and wrong now.

### Summarizer API

```javascript
const summarizer = await Summarizer.create();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Specialized APIs should also be accessed via the ai namespace (e.g., ai.summarizer.create()) rather than using the interface name as a global.

Suggested change
const summarizer = await Summarizer.create();
const summarizer = await ai.summarizer.create();
References
  1. Code examples in skill documentation should be minimal, demonstrating only the core SDK functionality. Avoid adding boilerplate like error handling, as the goal is to showcase SDK usage, not teach general coding practices.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Outdated and wrong now.

```javascript
const stream = session.promptStreaming('Write a poem about the ocean.');
for await (const chunk of stream) {
process.stdout.write(chunk);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

process.stdout.write is a Node.js-specific API and is not available in the browser or Chrome Extension environments where these APIs are used. Use console.log or a DOM-based output method instead.

Suggested change
process.stdout.write(chunk);
console.log(chunk);
References
  1. Code examples in skill documentation should be minimal, demonstrating only the core SDK functionality. Avoid adding boilerplate like error handling, as the goal is to showcase SDK usage, not teach general coding practices.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1, this should just be console.log(chunk);.

### Context Window Tracking

```javascript
console.log(`Context usage: ${session.contextUsage}/${session.contextWindow}`);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The LanguageModel session object uses tokensSoFar and maxTokens to track context usage, rather than contextUsage and contextWindow.

Suggested change
console.log(`Context usage: ${session.contextUsage}/${session.contextWindow}`);
console.log("Context usage: " + session.tokensSoFar + "/" + session.maxTokens);
References
  1. Code examples in skill documentation should be minimal, demonstrating only the core SDK functionality. Avoid adding boilerplate like error handling, as the goal is to showcase SDK usage, not teach general coding practices.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Outdated and wrong now.

All built-in AI APIs work in Chrome Extensions. For extensions using the Prompt API, you can customize model parameters:

```javascript
const params = await LanguageModel.params();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The method to retrieve model parameters and limits is capabilities(), not params(). Additionally, it should be called on the ai.languageModel factory.

Suggested change
const params = await LanguageModel.params();
const params = await ai.languageModel.capabilities();
References
  1. Code examples in skill documentation should be minimal, demonstrating only the core SDK functionality. Avoid adding boilerplate like error handling, as the goal is to showcase SDK usage, not teach general coding practices.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Outdated and wrong now.

@tomayac tomayac left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A solid start, however, here's significant overlap with:

The task API skills are not detailed enough.

Always check if the model is ready before creating a session:

```javascript
const availability = await LanguageModel.availability({

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is outdated and wrong now.

```javascript
const stream = session.promptStreaming('Write a poem about the ocean.');
for await (const chunk of stream) {
process.stdout.write(chunk);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1, this should just be console.log(chunk);.

### Context Window Tracking

```javascript
console.log(`Context usage: ${session.contextUsage}/${session.contextWindow}`);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Outdated and wrong now.

### Summarizer API

```javascript
const summarizer = await Summarizer.create();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Outdated and wrong now.

All built-in AI APIs work in Chrome Extensions. For extensions using the Prompt API, you can customize model parameters:

```javascript
const params = await LanguageModel.params();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Outdated and wrong now.

Comment on lines +332 to +338
## Enable on Localhost

1. Go to `chrome://flags/#optimization-guide-on-device-model` → **Enabled**
2. Go to `chrome://flags/#prompt-api-for-gemini-nano` → **Enabled** or **Enabled multilingual**
3. For multimodal input: `chrome://flags/#prompt-api-for-gemini-nano-multimodal-input` → **Enabled**
4. Restart Chrome
5. Verify: Open DevTools console, run `await LanguageModel.availability()`

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Obsolete now that the API ships in Chrome 148.


## Best Practices

1. **Always check availability** before creating a session — the model may not be downloaded yet

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, and with the exact same options you'll pass to create().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

client-side AI model (Gemini Nano) skill - Is it possible?

2 participants